<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
       xmlns:cadastros="http://java.sun.com/jsf/composite/components/cadastros"
      >
    <ui:composition template="template.xhtml">

        <ui:define name="dialogs">

              <p:dialog header="Cadastro de cliente" widgetVar="newCliente" modal="true" resizable="false"
                      width="650">
                     <h:panelGroup id="createFornecedor">
                             <cadastros:clienteComponent
                                 cliente="#{clienteBean.cliente}"
                                 buttonText="Criar"
                                 onclick_button_update=":clienteform :growl"
                                 onclick_sair_javascript="newCliente.hide()"
                                 buttonAction="#{clienteBean.save()}"
                                 />

                     </h:panelGroup>
                 </p:dialog>

        </ui:define>



        <ui:define name="content">
            <h:form id="clienteform">
              <h:panelGrid columns="2">
                        <h:outputText value="Nome do cliente:" styleClass="formLabel" style="width: 120px"/>
                        <p:inputText id="clienteName" style="width: 300px" value="#{centroCustoBean.centroCustoFilter}"
                                     onclick="jQuery(this).select()">
                            <p:ajax event="keyup" update="centroCustoList" />
                        </p:inputText>

                        <p:watermark for="clienteName" value="Digite o nome do cliente" />
                    </h:panelGrid>
              <h:panelGroup id="centroCustoList">
                  <p:dataTable var="client" value="#{clienteBean.listClients}"
                               paginator="true" rows="10" rowKey="#{client.id}"
                                     emptyMessage="Nenhum cliente foi encontrado"
                                     selectionMode="single" selection="#{clienteBean.clienteSelected}">

                            <p:ajax event="rowSelect" update="@this"/>

                            <f:facet name="header">
                                Lista de clientes
                            </f:facet>

                            <p:column style="width: 70%">
                                <f:facet name="header">
                                    <h:outputText value="Nome" />
                                </f:facet>
                                <h:outputText value="#{client.name}" />
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="telefone" />
                                </f:facet>
                                <h:outputText value="#{client.telefone}" />
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="E-mail" />
                                </f:facet>
                                <h:outputText value="#{client.email}" />
                            </p:column>


                            <f:facet name="footer">
                                <p:commandButton icon="ui-icon ui-icon-plus" title="Adicionar centro de custo" oncomplete="newCliente.show()" update=":createFornecedor"
                                                 disabled="#{not sharedPermissionManagedBean.hasPermission('CRIAR_CLIENTE')}"/>
                                <p:commandButton icon="ui-icon ui-icon-pencil" title="Editar centro de custo"
                                                 disabled="#{(not sharedPermissionManagedBean.hasPermission('EDITAR_CLIENTE')) or (empty fornecedorBean.fornecedorSelected)}"/>

                                <p:commandButton icon="ui-icon ui-icon-minus" title="Remover centro de custo"
                                                 disabled="#{(not sharedPermissionManagedBean.hasPermission('REMOVER_CLIENTE')) or (empty fornecedorBean.fornecedorSelected)}"/>

                            </f:facet>
                        </p:dataTable>
                    </h:panelGroup>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
